<template>
  <div class="loginBox">
    <div class="logo">
      <div class="textAndImg"></div>
      <div class="imgOne"></div>
    </div>
    <div class="seleteBox">
      <div class="back" @click="back">
        <div class="backIcon"></div>
        <div class="backText">返回登录</div>
      </div>
      <div class="userInfo">{{ `当前账户：${$store.state.user.name}` }}</div>
      <div class="line"></div>
      <div class="welcome">请选择进入的系统</div>
      <div class="welcomeText">请根据您的需求，选择默认进入的初始系统</div>
      <div class="line"></div>
      <div class="seleteArea">
        <div
          v-for="item in systemList"
          :key="item.menuId"
          :class="{ isSeleted: isSeleted === item.menuName }"
          class="seleteItem"
          @click="seleted(item)"
        >
          <div
            :class="item.menuName === '客户名单分配' ? 'itemTwo' : 'itemThree'"
            class="itemIcom"
          ></div>
          <span>{{ item.menuName }}</span>
        </div>
        <!-- <div class="seleteItem" :class="{'isSeleted':isSeleted===2}" @click="seleted(2)">
          <div class="itemIcom itemTwo"></div>
          <span>客户名单分配</span>
        </div>
        <div class="seleteItem" :class="{'isSeleted':isSeleted===3}" @click="seleted(3)">
          <div class="itemIcom itemThree"></div>
          <span>客户洞察</span>
        </div> -->
      </div>

      <el-button type="primary" @click="goSystem">进入系统</el-button>
    </div>
  </div>
</template>

<script>
import {getRouter, getSystemList} from "../api/login.js";
import {mapGetters} from "vuex";
import Cookies from "js-cookie";

export default {
  name: "systemSelected",
  data() {
    return {
      isSeleted: "客户运营",
      systemList: [],
      // name: 'CustomerOperations',
      path: '/customerOperations/home',
    };
  },
  mounted() {
  },
  computed: {
    ...mapGetters(['indexPage'])
  },
  methods: {
    async seleted(item) {
      console.log(item);
      if (this.isSeleted === item.menuName) {
      } else {
        this.isSeleted = item.menuName;
      }
      const {data} = await getRouter(item.menuId);
      // this.name = data[0].name
      // console.log(data, this.name)
      this.path = data?.[0]?.path + '/' + data?.[0]?.children?.[0].path
      // this.$router.push({
      //   name: data[0].name,
      // });
    },

    goSystem() {
      if (this.systemList.length == 1) {
        this.$router.push({path: this.indexPage || this.systemList[0].path})
      } else {
        this.$router.push({
          path: this.path
        });
      }
    },
    async getSystemList() {
      const {data} = await getSystemList();
      this.isSeleted = data[0].menuName;
      this.systemList = data;
    },
    back() {
      this.$store.dispatch("LogOut").then(() => {
        localStorage.clear()
        sessionStorage.clear()
        if(Cookies.get('userId')){
          Cookies.remove('UserId')
          Cookies.remove('Admin-Token')
        }
        location.href = window.globalConfig.BASE_URL;
      });
    }
  },
  created() {
    console.log(this.$route);
    this.getSystemList();
  },
};
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
.loginBox {
  width: 100%;
  height: 100%;
  display: flex;

  .logo {
    width: 48%;
    height: 100%;
    background-image: url("../assets/image/bg4.png");
    background-size: cover;

    .textAndImg {
      width: 641px;
      height: 330px;
      background-image: url("../assets/image/system.png");
      background-size: cover;
      margin: 0 auto;
    }

    .imgOne {
      width: 557px;
      height: 436px;
      background-image: url("../assets/image/logo.png");
      background-size: cover;
      margin: 20px auto;
    }
  }

  .seleteBox {
    width: 52%;
    padding: 78px 72px 0 60px;
    box-sizing: border-box;

    .back {
      display: flex;
      align-items: center;

      .backIcon {
        width: 24px;
        height: 24px;
        background-image: url("../assets/image/back.png");
        background-size: cover;
      }

      .backText {
        font-size: 16px;
        font-family: HarmonyOS_Sans_SC;
        color: #999999;
        margin-left: 21px;
      }
    }

    .userInfo {
      font-size: 18px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #2a2a2a;
      margin: 21px 0 16px;
    }

    .line {
      width: 700px;
      height: 1px;
      border: 1px solid #eeeeee;
    }

    .welcome {
      font-size: 24px;
      font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
      font-weight: bold;
      color: #2a2a2a;
      text-align: center;
      margin: 24px 0 14px;
    }

    .welcomeText {
      font-size: 14px;
      font-family: MicrosoftYaHei;
      color: #999999;
      text-align: center;
      margin-bottom: 25px;
    }

    .seleteArea {
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 85px 0 78px;

      .seleteItem {
        width: 183px;
        height: 219px;
        border-radius: 6px;
        border: 2px solid #eeeeee;
        padding: 30px 32px 0;
        text-align: center;
        font-size: 18px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #505050;

        .itemIcom {
          width: 118px;
          height: 112px;
          background-image: url("../assets/image/manage.png");
          background-size: cover;
          margin-bottom: 31px;
        }

        &:nth-child(2) {
          margin: 0 51px;
        }

        .itemTwo {
          background-image: url("../assets/image/allot.png");
        }

        .itemThree {
          background-image: url("../assets/image/see.png");
        }
      }
    }
  }
}

.el-button {
  width: 436px;
  height: 52px;
  background: #082aff;
  border-radius: 6px;
  margin-left: 150px;
}

.isSeleted {
  border: 2px solid #082aff !important;
  color: #082aff !important;
}
</style>
